#ifndef _APP_H_
#define _APP_H_

#include "sys.h"

#define LED 		PBout(9)
#define BUZZER 		PCout(13)
#define KEY 		PCin(14)

#define LED_ON		0
#define LED_OFF		1

//串口全局变量
//USART1:
extern float x_pep,wide_pep, target_y, Miny, Maxx, Minx, Maxw, Wide, High, cross_x, cross_y;
extern float rec_x,rec_y;
extern int object, eyestate, ripe, stop_flag, Dcenter_flag1, Dcenter_flag2, W_flag;
extern int Target_Len, Fruit_num, Cross_num, Rec_num, ctf;
extern float wlimit, ylimit;
extern double Sx1, Sx2, Sx3;
typedef struct
{
	int object,ripe;
	float X,Y,W,H,high,ratio;
}Fruit;
extern u8 flag_over;
extern Fruit fruit[12], fruit_rem;
//USART2:
extern int armstate, armmode; 
//USART3:
extern float left_x, left_y;
extern int leftstate, leftback, carstate;
extern uint8_t 	turn_flag,order_flag;
//UART4:
extern float right_x, right_y;
extern int rightstate, rightback;
//UART5:
extern float front_angle, left_distance, right_distance;
extern int  front_state;
extern int watchdog, control;
extern int Leida_count_A;
extern float Leida_Angle[20],Leida_Distance[4],Target_Leida_A;
//USART6:
extern u16 GrapFruitNum;
//HC_SR04,超声波距离
extern float d_left, d_right, remember_d_left,remember_d_right;
//SWLED（光电对管）
extern u8 SWLED_Flag;
//ELSE
extern int direction;
extern float speed_fast,speed_slow;
extern u16 step;

void order(int u, char Order);
void order_num(int u, char Order, float num);
void wait_w(int num, char Order, float N);
void Task(void);
int wait(int num);
void TaskAtoB(void);
void TaskBtoC(void);
void TaskCtoD(void);
void Taskend(void);
void FruitPrint(Fruit *f,int FruitNum);
//float MinY(int FruitNum);
void wait_s(void);
void AB0_CloseToFruit(float x_target,float y_target);
void AB1_CloseToFruit(float W_Target);
void CloseToCross(float x_target,float y_target,int dir);
void CloseToRec(float x_target,float y_target,int dir);
void Turn_180(void);
void TurnByLeiDa(float TargetAngle);
void BubbleSort_int16(float *a,int len);//冒泡排序
float LowPassFilter_RemoveExtremumAverage(float data[],int16_t length);//去极值的均值滤波
void GrapHighFruit_AB(uint8_t high);
void GrapLowFruit_AB(u8 dir);
int HighToNum(float high);
void CloseToWall(float Target_L,float Target_R,float Target_B);
char* intToString(int num,char *num_str);
#endif
